package server_io;

import java.io.InputStream;

/**
 * Request类表示一个HTTP请求
 */
public class Request {
    private InputStream input;
    private String uri;

    public Request(InputStream input) {
        this.input = input;
    }

    public void parse() {
        //Read a set of characters from the socket
        int i;
        byte[] buffer = new byte[2048];
        try {
            i = input.read(buffer);
        } catch (Exception e) {
            e.printStackTrace();
            i = -1;
        }
        String request = new String(buffer);
        int index1 = request.indexOf("/");
        int index2 = request.indexOf(" HTTP/1.1");
        uri = request.substring(index1, index2);
    }

    public String getUri() {
        return this.uri;
    }
}
